/**
* Created with IntelliJ IDEA.
*/


var ${bean.lowerClassName}_add_button='${bean.lowerClassName}_add_button';
var ${bean.lowerClassName}_modify_button='${bean.lowerClassName}_modify_button';
var ${bean.lowerClassName}_view_button='${bean.lowerClassName}_view_button';
var ${bean.lowerClassName}_delete_button='${bean.lowerClassName}_delete_button';

var ${bean.lowerClassName}_add_window='${bean.lowerClassName}_add_window';
var ${bean.lowerClassName}_modify_window='${bean.lowerClassName}_modify_window';
var ${bean.lowerClassName}_view_window='${bean.lowerClassName}_view_window';
var ${bean.lowerClassName}_grid_table='${bean.lowerClassName}_grid_table';
var ${bean.lowerClassName}_grid_toobar='${bean.lowerClassName}_grid_toobar';

var ${bean.lowerClassName}_url_gridData= Constants.ctx+ '${bean.lowerClassName}/getGridData.do';
var ${bean.lowerClassName}_url_add = Constants.ctx + "${bean.lowerClassName}/add.do";
var ${bean.lowerClassName}_url_edit = Constants.ctx + "${bean.lowerClassName}/edit.do";
var ${bean.lowerClassName}_url_view = Constants.ctx + "${bean.lowerClassName}/view.do";
var ${bean.lowerClassName}_url_deleteMore = Constants.ctx + "${bean.lowerClassName}/deleteMore.do";
var ${bean.lowerClassName}_url_save = Constants.ctx + "${bean.lowerClassName}/save.do";

$(document).ready(function () {
${bean.lowerClassName}_initGrid();
})
function ${bean.lowerClassName}_initGrid(){
var params = {};
params.elementId = ${bean.lowerClassName}_grid_table;
params.url = ${bean.lowerClassName}_url_gridData;
params.toolbar='#'+${bean.lowerClassName}_grid_toobar;
params.columns = [
[
{field: 'ck', checkbox: true},
{field: "id", title: "ID", width:100,align:'center',hidden:true},

<#list bean['fields'] as field>
${field.columnUI}
    <#if field_has_next>
    ,
    </#if>
</#list>
//{field: 'description', title: '备注', width:100,align:'center'},
//{field: 'createTime', title: '创建时间', width:100,align:'center'},
//{field: 'createUser', title: '创建人', width:100,align:'center'},
//{field: 'updateTime', title: '更新时间', width:100,align:'center'},
//{field: 'updateUser', title: '更新人', width:100,align:'center'} ,
//{field: 'operator', title: '操作', hidden: false, align: 'right', width:100,align:'center'
//}
]
];
Utils.initGrid(params);
}

//添加
function ${bean.lowerClassName}_add(){
Utils.openWindow(${bean.lowerClassName}_add_window);
$("#" + ${bean.lowerClassName}_add_window).load(${bean.lowerClassName}_url_add, function () {
var formObj = $(this).find('form').eq(0);
formObj.form('clear');
${bean.lowerClassName}_validation(formObj);
${bean.lowerClassName}_registeEvent(${bean.lowerClassName}_add_window);
})
}
//编辑
function ${bean.lowerClassName}_edit(){
function callBack(row) {
var urlParams = '?id=' + row.id;
Utils.openWindow(${bean.lowerClassName}_modify_window);
$("#" + ${bean.lowerClassName}_modify_window).load(${bean.lowerClassName}_url_edit + urlParams, function () {
${bean.lowerClassName}_initComplexObject(row);
var formObj = $(this).find('form').eq(0);
formObj.form('load', row);
${bean.lowerClassName}_validation(formObj);
${bean.lowerClassName}_registeEvent(${bean.lowerClassName}_modify_window);
})
}

Utils.doEdit(callBack, {elementId: ${bean.lowerClassName}_grid_table});
}
//删除
function ${bean.lowerClassName}_remove(){
function callBack(flag) {
}

Utils.doDeleteMore(callBack, {elementId: ${bean.lowerClassName}_grid_table, url: ${bean.lowerClassName}_url_deleteMore});
}
//查看
function ${bean.lowerClassName}_view(){
function callBack(row) {
Utils.openWindow(${bean.lowerClassName}_view_window);
var urlParams = '?id=' + row.id;
$("#" + ${bean.lowerClassName}_view_window).load(${bean.lowerClassName}_url_view + urlParams, function () {
${bean.lowerClassName}_initComplexObject(row);
var formObj = $(this).find('form').eq(0);
formObj.form('load', row);
formObj.find('input').each(function () {
$(this).attr('disabled', 'disabled');
$(this).attr('readonly', true);
})
${bean.lowerClassName}_registeEvent(${bean.lowerClassName}_view_window);
})
}

Utils.doView(callBack, {elementId: ${bean.lowerClassName}_grid_table});
}

function ${bean.lowerClassName}_validation(formObj) {
var conditions = {
//        id: {},
<#list bean['fields'] as field>
    <#if field.columnConditionUI != "">
    ${field.columnConditionUI},
    </#if>
</#list>
description: {}
//createTime: {element: 'datetimebox', formatter: Utils.formaterDateTime},
//createuser: {},
//updateTime: {element: 'datetimebox', formatter: Utils.formaterDateTime},
//updateuser: {}
};
Utils.initFormConditions(formObj, conditions);
}

function ${bean.lowerClassName}_registeEvent(windowId) {
var formObj = $('#' + windowId).find('form').eq(0);
$('#' + windowId).find(Constants.save_button).eq(0).off().on("click", function (e) {
var isValid = formObj.form('validate');
if (!isValid)
return;
$(this).attr('disabled', 'disabled');
var obj = {};
obj.formObj = formObj;
obj.url = ${bean.lowerClassName}_url_save;
function dealAjaxBack(data) {
Utils.closeWindow(windowId);
$.messager.alert('Info', data, 'info');
Utils.refreshGrid(${bean.lowerClassName}_grid_table);
}

obj.dealAjaxBack = dealAjaxBack;
Utils.submitForm(obj);
e.stopPropagation();
});

$('#' + windowId).find(Constants.reset_button).eq(0).off().on("click", function (e) {
Utils.resetForm(formObj);
e.stopPropagation();
});
}

function ${bean.lowerClassName}_initComplexObject(data) {
<#list bean['fields'] as field>
    <#if field.relationObject!="">
    data['${field.relationObject}.id'] = data.${field.relationObject}.id;
    data['${field.relationObject}.name'] = data.${field.relationObject}.name;
    </#if>
</#list>
}
